package com.intel.factorytest.ChamberMode;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.intel.factorytest.util.Util;
import com.intel.factorytest.util.LogUtils;
import android.content.ComponentName;
import android.os.SystemProperties;


public class ChamberModeReceiver extends BroadcastReceiver {

    private final String CHAMBER_RUN_PROP = "persist.sys.chamber_run";
    private final String CHAMBER_MODE_PROP = "persist.sys.chamber_mode";
    private final String CHAMBER_DIAGCMD_PROP = "persist.sys.chamber.diagcmd";
    private final String CHAMBER_BANDTEST_PROP = "persist.sys.chamber.bandtest";
    private final String FACTORY_TEST_PROP = "sys.cit.key.test";

    @Override
    public void onReceive(Context context, Intent intent) {
        LogUtils.logi("ChamberModeReceiver onReceive");
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            LogUtils.logi("receive boot complete");
            SystemProperties.set(FACTORY_TEST_PROP,"false");
            LogUtils.logi("receive shut down chamber run prop1 = " + SystemProperties.get(CHAMBER_RUN_PROP));
            SystemProperties.set(CHAMBER_RUN_PROP,"false");
            LogUtils.logi("receive shut down chamber run prop2 = " + SystemProperties.get(CHAMBER_RUN_PROP));
            SystemProperties.set(CHAMBER_DIAGCMD_PROP,"null");
            SystemProperties.set(CHAMBER_BANDTEST_PROP,"null");

            String chambermode = Util.getSystemProperties(CHAMBER_MODE_PROP, "null");
            LogUtils.logi(" chambermode = " + chambermode);
            if(chambermode.equals("Chamber")) {
                startChamberModeMainActivity(context);
            }
        } else {
            LogUtils.logi("do nothing ");
        }
    }

    private void startChamberModeMainActivity(Context context){
        /*
        Intent chamberModeIntent = new Intent();
        chamberModeIntent.setClassName("com.qualcomm.qti.qmmi",
                "com.qualcomm.qti.qmmi.testcase.ChamberMode.ChamberModeMainActivity");
        context.startActivity(chamberModeIntent);
        */

        Intent chamberModeIntent = new Intent(Intent.ACTION_MAIN);
        ComponentName cn = new ComponentName("com.intel.factorytest","com.intel.factorytest.ChamberMode.ChamberModeMainActivity"); 
        chamberModeIntent.setComponent(cn); 
        chamberModeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(chamberModeIntent);
    }
}
